//<script type='text/javascript'>

/////// LI FLOAT CLASS

float 	= {
	all			: {},
	_proto_		: {
	
		plus		: function() {
		
			console.log("plus");
		
			/*vars = win.float.list[this.parentNode.id];
			$('column_right').insert( new Win('asset.obj.'+vars.type+'.'+vars.id).request({tool:vars.tool, action:(vars.action)? vars.action:'edit', 'vars':vars }), {position:'after'});*/
		}
	
	
	}
}
		
	
var Li = function ( vars ) {
	id = 'float_' + vars.type + '.' + vars.id;
	
	if($(id)) li = $(id);
	else Object.extend(li = new Element("li", {id:id, class:"float_new", objtype:"float"}), float.li);
	
	li.vars = (vars)? vars : {};
	float.li.all[id] = li;

	li.observe( "mouseover", controls.bubble ).observe( "click", li.plus );
	
	return li.extend_by_type();
}

float.li	= {
	all		: {},
	objtype	: "float",
	extend_by_type	: function() {
	
		this.insert( inc = new Element("div", {'id':this.id+".inc", class:"inc" }) );
		this.insert( sub = new Element("span", { class:"sub" }) );
		this.insert( title = new Element("span", { class:"name" }) );
		
		//switch ( engine.type_r[this.vars.objtype] ) {
		switch ( this.vars.type ) {
		case "media.img" :
			this.addClassName( "img" );
			meta = this.vars.list[2].evalJSON();
			inc.setStyle({ background : "url(" + init.url + "/public.img?msk=1&lay=1&id=" + this.vars.list[0] + "&sze=78.20&rand=" + Math.random() + ") no-repeat" });
			title.update( this.vars.list[0] );
			sub.update( meta.raw );
			break;
			
		default		:
			title.update( this.vars.list[0] );
			sub.update( this.vars.list[1] );			
			break;
		}
		
		
		
		return this;
	}
}
Object.extend(float.li, float._proto_);


// FLOAT OBJECT
win.float = {
	list		: {},
	el			: function(vars) {
		//{id:1, type:'page', name:"home", descr:"", tool:"object.page", meta: {floats:[], subtype:'page', status:2}}
		id 		= 'float_'+vars.type+'.'+vars.id;
		obj 	= new Element('div',{'id':id, 'class':'float '+vars.type});
		kill 	= new Element("img",{'id':id+".kill",src: engine.path.img+"ico.close.png",'class':"ico"});
		plus 	= new Element("img",{'id':id+".plus",src: engine.path.img+"ico.plus.png",'class':"ico"});
		name 	= new Element("font",{id:id+".name","class":"name"+((vars.name)?"":" fill")}).update((vars.name)?vars.name:vars.descr);
		inc 	= new Element("div",{'id':id+".inc", class:"inc" });
		
		obj.appendChild(kill);
		obj.appendChild(plus);
		obj.appendChild(inc);
		if(vars.descr) obj.appendChild(new Element("font",{"class":"sub"}).update(vars.descr));
		obj.appendChild(name);
		win.float.extendsub(vars,obj,inc);
		if(vars.traceback) vars.traceback = [name.id];
		
		kill.observe('click',win.float.kill);
		plus.observe('click',(vars.meta.floats)? win.float.togglesub:win.float.plus);
		name.observe('click',win.float.plus);
		
		win.float.list[id] = vars;
		
		return obj;
	},
	
	extendsub	:function(vars,obj,inc) {
		// FLOAT WITH IMAGE REF
		if(["social.gmap", "text.news", "media.flash"].include(vars.tool) || vars.meta.img) {
			imgref = (vars.meta.img)? init.url+"/public.img?msk=1&lay=1&id="+vars.meta.img+"&sze=78.20" : "<?=CENTRAL?>img/sub."+vars.tool+".png";
			//inc.appendChild(new Element("img",{src:imgref}));
			inc.setStyle({background:"url("+imgref+") no-repeat"});
		
		// FLOAT WITH TEXT-SAMPLE
		} else if(vars.meta.filltext) {
			inc.addClassName("txt");
			inc.update(vars.meta.filltext);
		
		// FLOAT WITH SUBS (ie PAGE FLOAT)
		} else if(vars.meta.floats) {
			inc.observe("click", win.float.togglesub);
			inc.className = "minidrop";
			box = new Element("div", {'id':obj.id+".box", class:"box", style:"display:none; width:98%;"});
			obj.appendChild(box);
			inc.observe("click", win.float.togglesub);
			
			if(vars.meta.floats.length) inc.setStyle({background:"url("+engine.path.img+"float.line.subdrop."+((vars.meta.floats.length>9)?"n":vars.meta.floats.length)+".png)"});
			vars.meta.miniview = inc;
		}

	},
	
	togglesub	: function() {
		this.parentNode.toggleClassName("open");
		box = $(this.parentNode.id+".box").toggle();
		vars = win.float.list[this.parentNode.id];
		if(!win.asset.dropbox.typeref[vars.meta.subtype].include(box.id)) {
			vars.meta.floats = win.asset.dropbox.seed(box.id, vars.meta.floats, vars.meta.subtype);
			win.asset.dropbox.list[this.parentNode.id] = vars;
		}
	},
	
	plus		: function() {
		vars = win.float.list[this.parentNode.id];
		//if( vars.type == "mod" ) $('column_right').insert( new Win().request({ control:vars.control, action:(vars.action)? vars.action:'edit', 'vars':vars }));	
		$('column_right').insert( new Win('asset.obj.'+vars.type+'.'+vars.id).request({tool:vars.tool, action:(vars.action)? vars.action:'edit', 'vars':vars }), {position:'after'});
	
	},
	
	kill		: function() {
		vars = win.float.list[this.parentNode.id];
		xhttp.send('control.call.php', {trg:this.ancestors()[2].id+".comment", wtype:'push', tool:vars.tool, action:"kill", 'vars':vars});
		this.parentNode.remove();
		//xhttp.send('control.call.php', {trg:vars.id+".comment", wtype:'push', tool:vars.tool, action:"hierarchy", 'vars':vars});
	}
}

win.trfloat = function(vars) {
	obj = new Element("tr", {id:"float_"+vars.type+"."+vars.id, class:vars.class}).observe("click", (vars.local)? function(){ this.local(); }: function(){ this.plus(); });
	
	if(!vars.local) obj.observe("mouseover", function(){ this.linefloat(); });
	obj.vars = vars;
	
	vars.list.each(function(cell) { obj.appendChild(new Element('td').update((cell!="") ?((typeof cell == "object")?vars[cell.ref]:cell):'&nbsp;')); });
	
	return obj;
}

win.trfloat_methods = {
	linefloat	: function(el) {
		if(win.contr.linefloat.current != el) {
			$("linefloat").clonePosition(el, {setWidth:false, setHeight:true, offsetLeft:el.getWidth()-52, offsetTop:0});
			win.contr.linefloat.current = el;
			$("linefloat").show();
		}
    },
	plus		: function(el) {
		$('column_right').insert( new Win('asset.obj.'+el.vars.type+'.'+el.vars.id).request({tool:el.vars.tool, action:(el.vars.action)? el.vars.action:'edit', vars:el.vars}), {position:'after'});
	},
	local		: function(el) {
		$(el.vars.local+".value").update(el.vars.name);
		Object.extend(el.vars.meta = $(el.vars.local).vars.meta, {value:el.vars.id, field:el.vars.meta.parentfield, objid: el.vars.meta.parentid});
		el.vars.type = el.vars.meta.parenttype;

		xhttp.send('control.call.php', {trg:$(el.vars.local).ancestors()[3].id+".comment", wtype:'push', tool:el.vars.tool, action:'shift', 'vars':el.vars});
	},
	clone		: function(el) {
		
	},
	kill		: function(el) {
		xhttp.send('control.call.php', {trg:el.ancestors()[4].id + ".comment", wtype:'push', tool:el.vars.tool, action:"kill", 'vars':el.vars});
		el.remove();
		//xhttp.send('control.call.php', {trg:vars.id+".comment", wtype:'push', tool:vars.tool, action:"hierarchy", 'vars':vars});
	}
}

Element.addMethods("TR", win.trfloat_methods);






















